package cn.dbqn.controller;

import cn.dbqn.entity.Supplierinfo;
import cn.dbqn.entity.View_gsxx;
import cn.dbqn.service.SupplierinfoService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


@Controller
public class SupplierinfoController {

    @Resource
    SupplierinfoService supplierinfoService;
    // 设置访问路由值为路径

    @RequestMapping("/listsl")
    public String list(Model model){
        List<View_gsxx> list=supplierinfoService.findAllGs();
        model.addAttribute("list",list);
        return "lyear_ui_buttons";
    }

    //查询单个供商信息
    @ResponseBody
    @RequestMapping("gsxx")
    public Object gsxx(@RequestParam("sno")Integer sno){
        View_gsxx gsxx=supplierinfoService.gsxx(sno);
        return gsxx;
    }
    //新增供商信息
    @ResponseBody
    @RequestMapping("/addgsxx")
    public Object addGsxx(@RequestParam("sname")String sname,
                          @RequestParam("typeno")Integer typeno,
                          @RequestParam("slinkman")String slinkman,
                          @RequestParam("scontactway")String scontactway,
                          @RequestParam("saddress")String saddress,
                          @RequestParam("sremark")String sremark){
        Supplierinfo supplierinfo=new Supplierinfo();
        supplierinfo.setSname(sname);
        supplierinfo.setTypeno(typeno);
        supplierinfo.setSaddress(saddress);
        supplierinfo.setScontactway(scontactway);
        supplierinfo.setSlinkman(slinkman);
        supplierinfo.setSremark(sremark);
        int isflag=supplierinfoService.addGsxx(supplierinfo);
        return isflag;
    }
    //删除供商信息
    @ResponseBody
    @RequestMapping("/deletegsxx")
    public Object addGsxx(@RequestParam("sno")Integer sno){
        int isflag=supplierinfoService.deleteGsxx(sno);
        return isflag;
    }
    //修改供商信息
    @ResponseBody
    @RequestMapping("/updateGsxx")
    public Object updateGsxx(@RequestParam("sno")Integer sno,
                             @RequestParam("sname")String sname,
                             @RequestParam("typeno")Integer typeno,
                             @RequestParam("slinkman")String slinkman,
                             @RequestParam("scontactway")String scontactway,
                             @RequestParam("saddress")String saddress,
                             @RequestParam("sremark")String sremark){
        System.out.println("进入修改方法");
        int isflag=supplierinfoService.deleteGsxx(sno);
        return isflag;
    }
}
